#include "time.h"
#include <iostream>
#include <ctime>
using std::cout, std::cin, std::endl, std::ostream, std::istream;

Date::Date(int _year, int _month, int _day,
    int _hour, int _min)
    : year(_year), month(_month), day(_day), 
    hour(_hour), min(_min) {}
Date::Date(){;}

ostream& operator<<(ostream& out, const Date& date) {
    out << date.getYear() << "-" << date.getMonth() << "-" << date.getDay() 
        << " " << date.getHour() << ":" << date.getMin();
    return out;
}

istream& operator>>(istream& in, Date& date) {
    in >> date.year;
    if (in.get() != '-') {
        in.setstate(std::ios::failbit);
        return in;
    }
    in >> date.month;
    if (in.get() != '-') {
        in.setstate(std::ios::failbit);
        return in;
    }
    in >> date.day;
    if (in.get() != ' ') {
        in.setstate(std::ios::failbit);
        return in;
    }
    in >> date.hour;
    if (in.get() != ':') {
        in.setstate(std::ios::failbit);
        return in;
    }
    in >> date.min;
    return in;
}

void Date::setDate(){ 
    cout << "请输入年份:";
    cin >> year;
    cout << "请输入月份:";
    cin >> month;
    cout << "请输入发车日期:";
    cin >> day;
    cout << "请输入发车时间(小时):";
    cin >> hour;
    cout << "请输入发车时间(分钟):";
    cin >> min; 
}

bool Date::dateLaterThan(const Date& other) const{
    if(year > other.getYear()) return true;
    if(month > other.getMonth()) return true;
    if(day > other.getDay()) return true;
    if(hour > other.getHour()) return true;
    if(min > other.getMin()) return true;
    return false;
}

